package utils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MDGenerator {
	public static String md5(String data) {
	    try {
	        MessageDigest md = MessageDigest.getInstance("MD5");
	        byte[] md5 = md.digest(data.getBytes(StandardCharsets.UTF_8));
	        
	        // 将处理后的字节转成 16 进制，得到最终 32 个字符
	        StringBuilder sb = new StringBuilder();
	        for (byte b : md5) {            
	             sb.append(String.format("%02x", b));
	        }
	        return sb.toString();
	    } catch (NoSuchAlgorithmException e) {
	        e.printStackTrace();
	    }
	    return "";
	}
}
